<?php
namespace Common\Models;
use Common\BaseModel;
use Common\Common;

class BShopGoodsComment extends BaseModel
{
    public $res;
    public $expire;

    public function initialize()
    {
        parent::initialize();
        $this->setSource('b_shop_goods_comment');
    }

    /**
     * 查看用户是否已经存在
     */
    public function exit_user_comment($user_id,$order_sn)
    {
        $conditions = "user_id='{$user_id}' AND order_sn='{$order_sn}'";
        $exit_comment = $this->findFirst(array(
            $conditions,
        ));
        return $exit_comment;
    }



    /**
     * 获取商品的好评率
     */
    public function goods_comment_rate($goods_id){
        $condtions="goods_id={$goods_id}";
        $all_comment = $this->count(array(
            $condtions
        ));
        $condtions .= " AND star>=4";
        $goods_comment = $this->count(array(
            $condtions
        ));
        $goods_rate = $goods_comment && $all_comment ? ($goods_comment / $all_comment) * 100 : 0;
        return Common::number_randtwo($goods_rate);
    }
}
